from enum import Enum


class AppState(Enum):
    # 状态表
    # normal: 常规模式
    NORMAL = 0
    # VERTEX_MEASURE: 几何顶点距离测量模式
    VERTEX_MEASURE = 1
    # 渲染物理量云图
    ATTRIBUTE_MODE = 2


class StateMachine:

    _state = AppState.NORMAL
    # 当前被选中的cell 信息
    selected_cells = None

    def __init__(self):
        self.selected_cells = []

    def add_select_cell(self, cell):
        self.selected_cells.append(cell)

    def remove_select_cell(self, cell_index):
        self.selected_cells = [
            x for x in self.selected_cells if x["cell_index"] != cell_index
        ]

    def is_cell_selected(self, cell_index):
        result = [x for x in self.selected_cells if x["cell_index"] == cell_index]
        return len(result) > 0

    def to_normal(self):
        self._state = AppState.NORMAL

    # TODO
    def to_geo_point_select(self):
        self._state = "geo_point_select"

    def to_attribute(self):
        self._state = AppState.ATTRIBUTE_MODE

    def get_current_state(self):
        return self._state
